package helpers;

import org.mindrot.jbcrypt.BCrypt;

/**
 * The HashHelper class contains a set of helper methods for hashing.
 * 
 * @author Mattias
 * 
 */
public class HashHelper {
	
	/**
	 * Creates a BCrypt hashed password from a plain text password.
	 * 
	 * @param plainPassword The plain text password
	 * @return The hashed password
	 */
	public static String createPassword(String plainPassword) {
		return BCrypt.hashpw(plainPassword, BCrypt.gensalt());
	}
	
	/**
	 * Validates a plain text password against a BCrypt hashed password.
	 * 
	 * @param plainPassword The plain text password
	 * @param hashedPassword The BCrypt hashed password
	 * @return <code>true</code> if the plain text password matched the hashed password, <code>false</code> otherwise.
	 */
	public static boolean validatePassword(String plainPassword, String hashedPassword) {
		return BCrypt.checkpw(plainPassword, hashedPassword);
	}
	
}
